package com.kjzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kjzy.mapper.ReservationMapper;

import com.kjzy.pojo.Reservation;
import com.kjzy.service.ReservationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ReservationServiceImpl implements ReservationService {
    @Autowired
     private ReservationMapper reservationMapper;


    public Reservation findByid(int id) {
        return reservationMapper.findById(id);
    }

    public PageInfo<Reservation> findAllB(Reservation reservation, int pageNum, int pageSize) {
        //pageNum:当前页   pageSize：每页条数
        PageHelper.startPage(pageNum,pageSize);
        // 调用MyBatis的Mapper方法进行查询
        List<Reservation> reservationList=reservationMapper.findAllM(reservation);
        // 返回分页信息
        return new PageInfo<Reservation>(reservationList);
    }


    public String deleteReservation(int id) {
        // 1. 删除一个用户
        // 1-1.调用数据访问层(持久层)userMapper的deleteUserById方法，
        // 在用户表中删除一条用户记录。
        int rows = this.reservationMapper.deleteReservation(id);
        // 2-2.判断删除用户是否成功。如果删除用户成功，则返回"SUCCESS"，
        // 否则返回失败信息。
        if (rows > 0) {
            return "SUCCESS";
        } else {
            return "delete user failure.";
        }
    }

}
